<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<#include "../../common/res.html">
		
		<script type="text/javascript">
			var rowCount = <#if !pagination.items?? > ${0} <#else> ${(pagination.items?size)!} </#if>;
			var id_sbj = ${RequestParameters["id_sbj"]};
			function doAdd(){
				var rowNum = rowCount;
				
				var tr = $("<tr></tr>");
				$("#item_data").append(tr);
				
				tr.attr("id","item_data_"+rowNum);
				if(rowNum%2 != 0){
					tr.addClass("even-tr");
				}
				
				var td_id = $("<input id='id' type='hidden'/>");
				tr.append(td_id);
				
				var td_idSbj = $("<input id='idSbj' type='hidden'/>");
				tr.append(td_idSbj);
				
				var td_name = $("<td><input id='name' type='text' /></td>");
				tr.append(td_name);
				
				var td_content = $("<td><input id='content' type='text' /></td>");
				tr.append(td_content);
				
				var td_type = $("<td> <select id='type' >"+
						"<option value ='varchar'  selected='selected'>varchar</option>" +
						"<option value ='blob'>blob</option>" +
						+"</select></td>");
				tr.append(td_type);
				
				var td_creater = $("<td><input id='creater' type='text' /></td>");
				tr.append(td_creater);
				
				var td_createtime = $("<td><input id='createtime' type='hidden' /></td>");
				tr.append(td_createtime);
				
				var td_btn = $("<td>"+
						"<a href='javascript:void(0);' onclick='doSave("+rowNum+")'>保存</a>&nbsp;&nbsp;"+
						+"</td>");
				tr.append(td_btn);
				
				rowCount= rowCount+1;
				
			}
			function doDelete(rowIndex){
				if(confirm("确定删除?")){
					var id = $("#item_data_"+rowIndex).find("#id").val();
					$.ajax({
						url:'${s.base}/item/delete.html' ,
					    type:'POST',
					    data:{id:id},
					    success:function(data){
					    	var errcode = data.errcode;
					    	if(errcode == 0){//没有错误
					    		 location.reload();
					    	}
					    } ,
					    dataType:'json'
					});
				}
			}
			function doSave(rowIndex){				
				var id = $("#item_data_"+rowIndex).find("#id").val();
				var idSbj = id_sbj;
				var name = $("#item_data_"+rowIndex).find("#name").val();
				var content = $("#item_data_"+rowIndex).find("#content").val();
				var type = $("#item_data_"+rowIndex).find("#type").val();
				var creater = $("#item_data_"+rowIndex).find("#creater").val();
				
				if(name==""){
					alert("数据项名不能为空");
					return;
				}
				
				$.ajax({
					url:'${s.base}/item/toMerge.html' ,
				    type:'POST',
				    data:{id:id,idSbj:idSbj,name:name,content:content,type:type,creater:creater},
				    success:function(data){
				    	var errcode = data.errcode;
				    	var sign = data.data;
				    	if(errcode == 0){//没有错误
				    		 location.reload();
				    	}else if(errcode == 1){
				    		alert(data.message);
				    	}
				    },
				    dataType:'json'
				});
			}
		</script>
	</head>
	
	<body class="bg">
		<#include "../../common/top.html">
		
		<div class="content">
			<div class="block-nav">
				<#include "../../common/nav.html">
			</div>
			
			<div class="block-content" >
			
				<div class="block-content-nav">
					<span class="title">专题管理 </span>
				</div>
				
				<div class="block-content-description">
					<span>
						数据项管理
					</span>
				</div>
				<form id="queryPageForm" action="${s.base}/item/itemManager.html">
				<div class="block-content-content">
					<table class="fm-table">
						<thead>
							<tr >
								<td >数据项名</td>
								<td >说明备注</td>
								<td >类型</td>
								<td >创建人</td>
								<td >创建时间</td>
								<td >
									<input class="btn" onclick="doAdd()" type="button" value="添 加"/>
								</td>
							</tr>
						</thead>
						<tbody id="item_data">
							<input id="id_sbj" name="id_sbj" type="hidden" value="${RequestParameters['id_sbj']!}"/>
							<#if pagination.items?? >
							<#list pagination.items as row>
							<#if row_index %2 == 0>
							<tr id="item_data_${row_index!}">
							<#else>
							<tr class="even-tr" id="item_data_${row_index!}">
							</#if>
								<input id="id" type="hidden" value="${row.id!}"/>
								<input id="idSbj" type="hidden" value="${row.idSbj!}"/>
								<td><input id="name" type="text" value="${row.name!}"/></td>
								<td><input id="content" type="text" value="${row.content!}"/></td>
								<td>
									<select id="type" >
										<option value ="varchar" <#if row.type=="varchar"> selected="selected" </#if>>varchar</option>
										<option value ="blob" <#if row.type=="blob"> selected="selected" </#if>>blob</option>
									</select>
								</td>
								<td ><input id="creater" type="text" value="${row.creater!}"/></td>
								<td ><input id="createtime" type="hidden" value="${row.createtime?datetime}"/>${row.createtime?string("yyyy-MM-dd")}</td>
								<td>
									<a href="javascript:void(0);" onclick="doSave(${row_index})">保存</a>
									<a href="javascript:void(0);" onclick="doDelete('${row_index}')">删除</a>&nbsp;&nbsp;
								</td>
							</tr>
							</#list>
							</#if>
						</tbody>
					</table>
					<#include "../../common/pagination.html">
				</div>
				</form>
			</div>
			<div class="clearfloat"></div>
		</div>
		
		<#include "../../common/footer.html">
	</body>
	
</html>
